package com.superman.service.socket;

import com.superman.service.impl.QueryImpl;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Properties;

public class TCPServer {
    private static ServerSocket serverSocket;
    private static int port;

    static {
        Properties properties = new Properties();
        try {
            properties.load(TCPServer.class.getResourceAsStream("serversocketinfo.properties"));
            port = Integer.valueOf(properties.getProperty("port"));
            serverSocket = new ServerSocket(port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println("======服务端已启动======");

        new QueryImpl().adminQueryRecord();

        while (true){
            try {
                Socket socket = serverSocket.accept();
                HandleThread thread = new HandleThread(socket);
                thread.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
